<script setup>
import { constant } from 'lodash'
import { reactive } from 'vue-demi'

const { proxy } = getCurrentInstance()
const ruleFormRef = ref(null)
const newRef = ref(null)
const props = defineProps({})

// tabs默认值
const activeName = ref('1')

const rightText = ref('')

// 新增表单 字段
const planForm = reactive({
  programmeCode: '', //方案代码
  b: '',
  programmeName: '', //方案名称
  programmeView: '', //方案描述
  defaultFlag: '2', //默认标志
  idList: '', //策略信息id
  strategyMessageList: [
    {
      id: '', //id(序号)
      strategyCode: '', //策略代码
      strategyDeliver: '', //发货策略
      enable: '0', //是否启用
      strategyView: '' //策略描述
    }
  ]
})

// 新增表单 校验规则
const addrules = reactive({
  a: [{ required: true, message: '请输入', trigger: 'blur' }]
})
// 回显数据赋值
watchEffect(() => {
  if (typeof props.ruleForm == 'object' && props.ruleForm?.id) {
    for (let Key in props.ruleForm) {
      planForm[Key] = props.ruleForm[Key]
    }
  }
})

// 提交数据
const submit = () => {
  return new Promise((resolve, reject) => {
    newRef.value.validate(valid => {
      if (!valid) {
        proxy.warningMsg('请填写完整')
        resolve(false)
      } else {
        resolve(planForm)
      }
    })
  })
}
defineExpose({ submit })
</script>

<template>
  <div class="app-container">
    <!-- 计划下达 表单 -->
    <el-form :model="planForm" label-width="120px" class="demo-ruleForm" status-icon inline ref="newRef">
      <el-table v-loading="loading" stripe border :data="planForm.strategyMessageList">
        <el-table-column type="selection" width="55" align="center" fixed="left" />
        <el-table-column label="序号" width="70" type="index" align="center" />
        <el-table-column label="采购计划单号" align="center" prop="pdoductNumber" width="210"> </el-table-column>
        <el-table-column label="备件编码" align="center" width="auto" prop="itemCode"> </el-table-column>
        <el-table-column label="备件名称" prop="materialCode" width="auto" align="center" />
        <el-table-column label="备件规格" prop="netWeight" width="auto" align="center" />
        <el-table-column label="备件单位" prop="netWeight" width="auto" align="center" />
        <el-table-column label="计划数量" prop="netWeight" width="auto" align="center" />
        <el-table-column label="下达数量" prop="strategyCode" width="200" align="center">
          <template #default="scope">
            <el-input
              type="number"
              oninput="if(value<=0)value=''"
              v-model="scope.row.strategyCode"
              placeholder="请填写内容"
            />
          </template>
        </el-table-column>
      </el-table>
      <div class="formclass">
        <el-form-item label="备件计划单价">
          <el-input v-model="planForm.programmeName" placeholder="请输入备件名称" />
        </el-form-item>
        <el-form-item label="下达总数量">
          <el-input v-model="planForm.programmeName" placeholder="请输入备件名称" />
        </el-form-item>
      </div>
    </el-form>
  </div>
</template>
<style lang="scss" scoped>
.title {
  color: #3985fb;
}
label {
  display: inline-block;
  width: 120px;
  text-align: right;
  padding-right: 12px;
}
.app-container ::v-deep .el-input__inner {
  width: 168px !important;
}

.app-container ::v-deep .el-form-item__content {
  width: 168px !important;
}

.formclass {
  margin-top: 25px;
}
</style>
